﻿#!/usr/bin/env python
# -*- coding: UTF-8 -*-

'''
Copyright (C) 2010 dbzhang800@gmail.com
All rights reserved.
'''
import math
from PySide import QtCore, QtGui

def calcLA(depth, ta, m, d):
    t = (d/2.0)/(depth+ta+0.0642+m)
    return math.pi*t*t*1000

print '='*20
print calcLA(4.82, 0.85, 1.98,0.15)
print '='*20

class Widget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(Widget, self).__init__(parent)
        self.setWindowTitle(u"G3 G7 电流计算")
        self.titleLabel = QtGui.QLabel(u"Ia = π*[（光澜直径/2）/(光澜深度depth+T/A +0.0642+阳极厚度)]^2*1000 (nA)\nG7阳极厚度默认为零")
        
        self.depthEdit = QtGui.QDoubleSpinBox()
        self.depthEdit.setValue(4.82)
        self.depthEdit.setDecimals(3)
        self.depthEdit.setSuffix(' mm')
        
        self.taEdit = QtGui.QDoubleSpinBox()
        self.taEdit.setValue(0.85)
        self.taEdit.setDecimals(3)
        self.taEdit.setSuffix(' mm')
        
        self.mEdit = QtGui.QDoubleSpinBox()
        self.mEdit.setValue(1.98)
        self.mEdit.setDecimals(3)
        self.mEdit.setSuffix(' mm')
        
        self.dEdit = QtGui.QDoubleSpinBox()
        self.dEdit.setValue(0.15)
        self.dEdit.setDecimals(3)
        self.dEdit.setSuffix(' mm')
        
        self.resultEdit = QtGui.QDoubleSpinBox()
        self.resultEdit.setDecimals(5)
        self.resultEdit.setSuffix(' uA')
        
        self.okButton = QtGui.QPushButton(u"计算")
        form = QtGui.QFormLayout()
        form.addRow(self.titleLabel)
        form.addRow(u"光阑深度",  self.depthEdit)
        form.addRow(u"T/A",  self.taEdit)
        form.addRow(u"阳极厚度", self.mEdit)
        form.addRow(u"光阑直径",  self.dEdit)
        form.addRow(u"结果",  self.resultEdit)
        form.addRow(u"",  self.okButton)
        self.setLayout(form)
        self.okButton.clicked.connect(self.onCalc)
    def onCalc(self):
        try:
            res = calcLA(self.depthEdit.value(), self.taEdit.value(), self.mEdit.value(), self.dEdit.value())
        except:
            res = 0
        self.resultEdit.setValue(res)

if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    w = Widget()
    w.show()
    sys.exit(app.exec_())